package ru.hh.team02.chat.database;

import ru.hh.team02.chat.messaging.PrivateMessage;

import java.util.List;


public interface DatabaseServiceInterface {
    /**
     * Check existance of client by his name.
     * @param name Client name whose name is checked.
     * @return
     */
    boolean clientExists(String name);

    /**
     * Get client password.
     * @param name Client name whose password is expected.
     * @return password
     */
    String getPasswordByClientName(String name);

    /**
     * Get the last room the client was it
     * @param name Client name
     * @return Room
     */
    String getRoomNameByClientName(String name);
    
    /**
     * Put a newly created personal message into database.
     * @param message Message to be put into database.
     * @return id of the database entry this message will be stored
     * into.
     */
    int putNewPersonalMessageIntoDatabase(String message, String recepientName);
    
    /**
     * Mark previously put message into the database as delivered.
     * (Depending on the policy of concrete implementation, it
     * may be deleted as soon as possible, or may be just marked
     * as deleted for optimization).
     * @param id Message ID to be marked as delivered
     * @return <code>true</code> - if the message has been successfully marked
     * <code>false</code> - if the id was missing or some other problems have emerged.
     */
    boolean markPersonalMessageAsDelivered(int id);
    
    /**
     * Get all the messages addressed to a provided client
     * from the database which haven't been
     * marked as received.
     * @param clientName Client name, who these messages have been
     * addressed to.
     * @return Ordered list of messages (in temporal order by time
     * they were added to the database)
     */
    List<PrivateMessage> getAllUndeliveredMessagesToTheClient (String clientName);

    /**
     * Get message from the database by ID
     * @param id ID of the message entry
     * @return MessageDbEntry
     */
    PrivateMessage getMessagesById (int id);

    /**
     * Get all rooms from the database
     * @return Array of rooms
     */
    String[] getAllRooms();

    /**
     * Save new client room to the DB.
     * @param clientName Client name
     * @param room New client room to save to the DB.
     */
    void changeRoom(String clientName, String room);
}
